package com.lzy.mall.coupon.controller;


//import com.benyun.boot.core.vo.ResultVO;
//import com.benyun.boot.core.util.ResultUtil;

import com.lzy.mall.common.utils.PageUtils;
import com.lzy.mall.common.utils.ResultUtils;
import lombok.RequiredArgsConstructor;

import java.util.Map;

import org.beetl.sql.core.engine.PageQuery;
import com.lzy.mall.coupon.utils.ParamsPageUtils;
import com.lzy.mall.coupon.entity.SmsHomeAdv;
import com.lzy.mall.coupon.service.SmsHomeAdvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lzy
 * create on 2021-10-14 11:13:16
 */
@RestController
@RequestMapping("homeadv")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class SmsHomeAdvController {
    /**
     * 服务对象
     */
    private final SmsHomeAdvService smsHomeAdvService;

    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    @RequestMapping("/list")
    public ResultUtils<?> queryAll(@RequestParam Map<String, Object> params) {
        PageQuery pageQuery = ParamsPageUtils.paramsToPage(params);
        PageQuery query = smsHomeAdvService.queryByPage(pageQuery);

        PageUtils pageUtils = new PageUtils(query);
        return ResultUtils.ok().put("page", pageUtils);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping("/info/{id}")
    public ResultUtils<?> queryOne(@PathVariable Long id) {
        SmsHomeAdv homeAdv = smsHomeAdvService.queryById(id);
        return ResultUtils.ok().put("homeAdv",homeAdv);
    }

    /**
     * 新增数据
     *
     * @param smsHomeAdv 实体对象
     * @return 新增结果
     */
    @RequestMapping("/save")
    public ResultUtils<?> create(@RequestBody SmsHomeAdv smsHomeAdv) {
        smsHomeAdvService.insert(smsHomeAdv);
        return ResultUtils.ok();
    }

    /**
     * 修改数据
     *
     * @param smsHomeAdv 实体对象
     * @return 修改结果
     */
    @RequestMapping("/update")
    public ResultUtils<?> update(@RequestBody SmsHomeAdv smsHomeAdv) {
        smsHomeAdvService.updateById(smsHomeAdv);
        return ResultUtils.ok();
    }

    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @RequestMapping("/delete")
    public ResultUtils<?> delete(@RequestBody List<Long> id) {
        smsHomeAdvService.deleteById(id);
        return ResultUtils.ok();
    }
}
